package com.jziver.library.repository;

import com.jziver.library.entiry.LibraryCard;
import com.jziver.library.entiry.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * Created by Administrator on 2016/7/6.
 */
public interface UserRepository extends JpaRepository<User,Integer> {


    @Query(value = "SELECT u FROM User u WHERE u.username=:username and u.password=:password")
    User login(@Param("username") String username, @Param("password") String password);


    @Modifying
    @Query("UPDATE User u SET u.libraryCard=:card WHERE u.id=:uid")
    void addLibraryCard(@Param("uid") Integer uid, @Param("card") LibraryCard card);  //添加借书证

    User findUserByUsername(String usename);   //检测用户名是否已存在
}
